//
//  StrongReminderView.m
//  NtoccShipper
//
//  Created by zcj on 2021/8/10.
//  Copyright © 2021 zhuchongjin. All rights reserved.
//

#import "StrongReminderView.h"
#import "CJDateTime.h"
#import "ShipperAuthVC.h"
#import "LogInVC.h"
#import "SourcesOrderListVC.h"
#import "SourcesOrderVC.h"
#import "SourceViewController.h"
#import "HomeVC.h"
#import "MineViewController.h"
#import "SourceListVC.h"
@interface StrongReminderView()

@property (nonatomic,strong) FlexFrameView *frameView;
@property (strong, nonatomic) CJImageView *imageVCode; // 图片验证码
@property (strong, nonatomic) CJTextField *fieldAouthCode;
@property (nonatomic,copy) OnSureClick sureBlock;
@property (nonatomic,copy) OnCancleClick cancleBlock;
@property (nonatomic,copy) NSString *strPhoneNum;
@end

@implementation StrongReminderView

+ (StrongReminderView *)shared {
    
    static dispatch_once_t predicate;
    static StrongReminderView *objc;
    
    dispatch_once(&predicate, ^{
        objc = [[StrongReminderView alloc] init];
    });
    
    return objc;
}
- (instancetype)init
{
    self = [super init];
    if (self) {
        
        CGFloat tabbarHeight  = [CJControl getCurrentViewController].hidesBottomBarWhenPushed == YES ?  0:kTabBarHeight;
//
//        if ([[CJControl getCurrentViewController] isKindOfClass:[SourcesOrderListVC class]]) {
//            tabbarHeight = 0;
//        }
//        if ([[CJControl getCurrentViewController] isKindOfClass:[SourcesOrderVC class]] || [[CJControl getCurrentViewController] isKindOfClass:[SourceViewController class]]) {
            tabbarHeight = kTabBarHeight;
//        }
        
        self.backgroundColor = [UIColor cjClearColor];
        [self addSubview:self.frameView];
        self.frame = CGRectMake(0, kScreenHeight - tabbarHeight - 55, kScreenWidth, 50);
    }
    return self;
}
//-(instancetype)initWithView{
//    
//    if (self = [super init]) {
//        
//        CGFloat tabbarHeight  = [CJControl getCurrentViewController].hidesBottomBarWhenPushed == YES ?  0:kTabBarHeight;
////
////        if ([[CJControl getCurrentViewController] isKindOfClass:[SourcesOrderListVC class]]) {
////            tabbarHeight = 0;
////        }
////        if ([[CJControl getCurrentViewController] isKindOfClass:[SourcesOrderVC class]] || [[CJControl getCurrentViewController] isKindOfClass:[SourceViewController class]]) {
//            tabbarHeight = kTabBarHeight;
////        }
//        
//        self.backgroundColor = [UIColor cjClearColor];
//        [self addSubview:self.frameView];
//        self.frame = CGRectMake(0, kScreenHeight - tabbarHeight - 55, kScreenWidth, 50);
//
//      }
//    
//      return self;
//}


- (FlexFrameView *)frameView{
    
    if (!_frameView) {
        CGRect rcFrame = CGRectMake(15,0, kScreenWidth - 30, 0);
        _frameView = [[FlexFrameView alloc] initWithFlex:@"StrongReminderView" Frame:rcFrame Owner:self];
        _frameView.flexibleHeight = YES;

        [_frameView layoutIfNeeded];
    }
    
    return _frameView;;
}

/// 展示隐藏
- (void)show {

//     全都展示逻辑
//    if ([[CJControl getCurrentViewController] isKindOfClass:[LogInVC class]]) {
//        return;
//    }
//    CJSaveMyDefault(StrongReminderTag, StrongReminderShow);
//
//    [[UIApplication sharedApplication].keyWindow addSubview:self];
//    [UIView animateWithDuration:0.5 animations:^{
//        self.alpha = 1.0;
//    }];
    
//     只有三个 tabbar item 的展示逻辑
    
    if ([[CJControl getCurrentViewController] isKindOfClass:[SourceListVC class]] || [[CJControl getCurrentViewController] isKindOfClass:[HomeVC class]] || [[CJControl getCurrentViewController] isKindOfClass:[MineViewController class]]) {
        
        if ([CJFetchMyDefault(StrongReminderTag) isEqualToString:StrongReminderShow]) {
        }else{
            CJSaveMyDefault(StrongReminderTag, StrongReminderShow);
        }

        [[UIApplication sharedApplication].keyWindow addSubview:self];
        [UIView animateWithDuration:0.5 animations:^{
            self.alpha = 1.0;
        }];
    }else{
        [self hidden];
    }
    
}

- (void)hidden {
    @weakify(self);
    [UIView animateWithDuration:0.5 animations:^{
        @strongify(self);
        self.alpha = 0.0;
    }];
}


/// 取消
- (void)btnTouchViewClickCancleAction{
    CJSaveMyDefault(StrongReminderTag, StrongReminderHide);
    [self hidden];
}
//确认
- (void)btnTouchViewClickSureAction{
    
    if ([[CJControl getCurrentViewController] isKindOfClass:[ShipperAuthVC class]]) {
        return;
    }
    
    [self pushVc:[ShipperAuthVC new]];
}

- (void)pushVc:(UIViewController *)vc {
    
    if ([vc isKindOfClass:[UIViewController class]] == NO) return ;
    if ([CJControl getCurrentViewController].navigationController == nil) return ;
    if (vc.hidesBottomBarWhenPushed == NO) {
        vc.hidesBottomBarWhenPushed = YES;
    }
    [[CJControl getCurrentViewController].navigationController pushViewController:vc animated:YES];
}
@end
